<template>
  
  <div class="content">
    <div class="gov-sub1">
      <div>
        <div class="gov-box">
          <div class="gov-title">
            <p>行政中心用电负荷分布图<i class="gl"></i><i class="gl"></i></p>
          </div>
          <chart :options="chart1" auto-resize></chart>
        </div>
        <div class="gov-box">
          <div class="gov-title">
            <p>行政中心用电负荷趋势<i class="gl"></i><i class="gl"></i></p>
          </div>
          <chart :options="chart2" :theme="chartTheme" auto-resize></chart>
        </div>
      </div>
      <div>
        <div class="gov-box gov-sub2-bottom">
          <div>
            <p>照明用电一周电量统计</p>
            <chart :options="chart3" :theme="chartTheme" auto-resize  ></chart>
          </div>
          <div>
            <p>暖通空调一周电量统计</p>
            <chart :options="chart4" :theme="chartTheme" auto-resize  ></chart>
          </div>
          <div>
            <p>动力用电一周电量统计</p>
            <chart :options="chart5" :theme="chartTheme" auto-resize  ></chart>
          </div>
          <div>
            <p>特殊用电一周电量统计</p>
            <chart :options="chart6" :theme="chartTheme" auto-resize  ></chart>
          </div>
        </div>
      </div>
    </div> 
  </div>
</template>

<script>
import echarts from 'echarts'
export default {
  name: 'governmentB',
  data () {
    return {
      chartTheme: {},
      chart1: {
        color: ['#0024e4','#9d4fff','#4bf7ff','#acfbff','#2ba0ff','#0b4dff'],
        tooltip : {
          trigger: 'item',
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
         show: false
        },  
        series : [
          {
            name:'用电负荷',
            type:'pie',
            radius : '75%',
            center: ['50%', '50%'],
            data:[
              {value:735, name:'暖通空调'},
              {value:310, name:'照明用电'},
              {value:274, name:'动力用电'},
              {value:235, name:'特殊用电'}
            ].sort(function (a, b) { return a.value - b.value; }),
            label: {
              normal: {
                textStyle: {
                  color: '#fff'
                }
              }
            },
            labelLine: {
              normal: {
                lineStyle: {
                  color: '#fff'
                },
                length: 10,
                length2: 60
              }
            }
          }
        ]
      },
      chart2: {
        color: ['#0024e4','#9d4fff','#4bf7ff','#4b4ddd'],
        tooltip : {
          trigger: 'axis',
          axisPointer: {
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        legend: {
          data: ['暖通空调','照明用电','动力用电','特殊用电']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis : [
          {
            type : 'category',
            boundaryGap : false,
            data : ['1:00','1:05','1:10','1:15','1:20','1:25','1:30','1:35','1:40','1:45','1:50','1:55','2:00','2:05'],
          }
        ],
        yAxis : [
          {
            name: '用电负荷（kW）',
            type : 'value',
          }
        ],
        series : [
        {
            name:'暖通空调',
            type:'line',
            stack: '总量',
            smooth: true,
            data:[120, 132, 101, 134, 90, 230, 210, 120, 132, 101, 134, 90, 230, 210],
          },
          {
            name:'照明用电',
            type:'line',
            stack: '总量',
            smooth: true,
            data:[220, 182, 191, 234, 290, 330, 310, 220, 182, 191, 234, 290, 330, 310],
          },
          {
            name:'动力用电',
            type:'line',
            stack: '总量',
            smooth: true,
            data:[150, 232, 201, 154, 190, 330, 410, 150, 232, 201, 154, 190, 330, 410],
          },
          {
            name:'特殊用电',
            type:'line',
            stack: '总量',
            smooth: true,
            data:[320, 332, 301, 334, 390, 330, 320, 320, 332, 301, 334, 390, 330, 320],

          },
        ]
      },
      chart3: {
        tooltip : {
          trigger: 'axis',
          axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis : [
          {
            type : 'category',
            data : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis : [
          {
            type : 'value',
          }
        ],
        series : [
          {
            name:'照明用电',
            type:'bar',
            barWidth: '20%',
            data:[10, 52, 200, 334, 390, 330, 220],
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1,[
                  {offset: 0, color: '#d358fc'},
                  {offset: 1, color: '#994dff'}
                ]),
              }
            }
          }
        ]
      },
      chart4: {
        tooltip : {
          trigger: 'axis',
          axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis : [
          {
            type : 'category',
            data : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis : [
          {
            type : 'value',
          }
        ],
        series : [
          {
            name:'暖通空调',
            type:'bar',
            barWidth: '20%',
            data:[10, 52, 200, 334, 390, 330, 220],
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1,[
                  {offset: 0, color: '#1e54f3'},
                  {offset: 1, color: '#0942e9'}
                ]),
              }
            }
          }
        ]
      },
      chart5: {
        tooltip : {
          trigger: 'axis',
          axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis : [
          {
            type : 'category',
            data : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis : [
          {
            type : 'value',
          }
        ],
        series : [
          {
            name:'动力用电',
            type:'bar',
            barWidth: '20%',
            data:[10, 52, 200, 334, 390, 330, 220],
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1,[
                  {offset: 0, color: '#4bf7ff'},
                  {offset: 1, color: '#0ed1df'}
                ]),
              }
            }
          }
        ]
      },
      chart6: {
        tooltip : {
          trigger: 'axis',
          axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis : [
          {
            type : 'category',
            data : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis : [
          {
            type : 'value',
          }
        ],
        series : [
          {
            name:'特殊用电',
            type:'bar',
            barWidth: '20%',
            data:[10, 52, 200, 334, 390, 330, 220],
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1,[
                  {offset: 0, color: '#7ffad1'},
                  {offset: 1, color: '#27f09a'}
                ]),
              }
            }
          }
        ]
      }
    }
  },
  mounted: function () {
    this.$http('/vqdisplay/static/HospitalChartTheme.json')
    .then( (response) => {
      this.chartTheme = response.data
    })
    this.getData()
  },
  methods: {
    getData: function () {
      this.$http('/vqdisplay/elect/data')
      .then( response => {
        let _data = response.data.body
        this.chart1.series[0].data = _data.current_elec_pie.series
        this.chart2.xAxis[0].data = _data.today_elec_line.xAxis
        this.chart2.series[0].data = _data.today_elec_line.series[0]['暖通空调']
        this.chart2.series[1].data = _data.today_elec_line.series[1]['照明用电']
        this.chart2.series[2].data = _data.today_elec_line.series[2]['动力用电']
        this.chart2.series[3].data = _data.today_elec_line.series[3]['特殊用电']

        this.chart3.xAxis[0].data = _data.light_bar.xAxis
        this.chart3.series[0].data = _data.light_bar.series[0]['照明用电']
        this.chart4.xAxis[0].data = _data.ac_bar.xAxis
        this.chart4.series[0].data = _data.ac_bar.series[0]['暖通空调']
        this.chart5.xAxis[0].data = _data.pd_bar.xAxis
        this.chart5.series[0].data = _data.pd_bar.series[0]['动力用电']
        this.chart6.xAxis[0].data = _data.sp_bar.xAxis
        this.chart6.series[0].data = _data.sp_bar.series[0]['特殊用电']
      })
    }
  }
}
</script>

<style scoped>
  @import '../../../style/government.css';
  .echarts {
    height: 80%;
    width: 100%;
  }
</style>